/**
 * @file field
 * @author fanxueliang@qq.com
 */
import type {HtmlSpecItem, RichTextField} from '../interface';
import {getBasicField} from '../util';
import {set, get, isBoolean} from 'lodash-es';

export function createRichTextField(spec: HtmlSpecItem, showIndex: number, path: string) {
    const excludesLinkTag = get(spec, 'rules.excludesLinkTag');
    // html 类型默认不能包含A标签
    if (!isBoolean(excludesLinkTag)) {
        set(spec, 'rules.excludesLinkTag', true);
    }

    const basicField = getBasicField(spec, path, showIndex);
    const tipText = basicField.tip ? basicField.tip : `请填写${spec.displayName}`;

    return {
        ...basicField,
        type: 'STRING',
        isLeaf: true,
        spec,
        tip: tipText,
        component: 'RichText'
    } as RichTextField;
}
